home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / NetHack 3.1.3 / source / sys / mac / dprintf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  1.3 KB  |  60 lines  |  [TEXT/R*ch]

  1. /*    SCCS Id: @(#)dprintf.c    3.1    93/05/14          */
  2. /* Copyright (c) Jon W{tte, 1993.                  */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include "hack.h"
  6.  
  7. #include <Types.h>
  8. #include <stdarg.h>
  9. #include <stdio.h>
  10. #ifndef THINK_C
  11. #include <strings.h>
  12. #endif
  13. #include <GestaltEqu.h>
  14.  
  15.  
  16. Boolean
  17. HasDebugger ( void ) {
  18. long osAttr ;
  19.     if ( Gestalt ( gestaltOSAttr , & osAttr ) ||
  20.         ! ( osAttr & ( 1 << gestaltSysDebuggerSupport ) ) ) {
  21.         return 0 ;
  22.     }
  23.     return 1 ;
  24. }
  25.  
  26.  
  27. Boolean
  28. KeyDown ( unsigned short code ) {
  29. unsigned char keys [ 16 ] ;
  30.  
  31.     GetKeys ( ( void * ) keys ) ;
  32.     return ( ( keys [ code >> 3 ] >> ( code & 7 ) ) & 1 ) != 0 ;
  33. }
  34.  
  35.  
  36. void
  37. dprintf ( char * format , ... ) {
  38. static char buffer [ 100 ] ;
  39. va_list list ;
  40. static Boolean checkedTrap = 0 ;
  41. static Boolean trapAvailable = 0 ;
  42.  
  43.     if ( ! checkedTrap ) {
  44.         checkedTrap = 1 ;
  45.         trapAvailable = HasDebugger ( ) ;
  46.     }
  47.     list = va_start ( list , format ) ;
  48.     vsprintf ( & buffer [ 1 ] , format , list ) ;
  49.     va_end ( list )  ;
  50.     buffer [ 0 ] = strlen ( & buffer [ 1 ] ) ;
  51.     if ( trapAvailable ) {
  52.         if ( KeyDown ( 0x39 ) ) {                                    /* Caps Lock */
  53.             DebugStr ( (uchar *) buffer ) ;
  54.         } else if ( KeyDown ( 0x3B ) && flags . window_inited &&    /* Control */
  55.             ( WIN_MESSAGE != -1 ) && theWindows [ WIN_MESSAGE ] . theWindow ) {
  56.             pline ( "%s" , & buffer [ 1 ] ) ;
  57.         }
  58.     }
  59. }
  60.